<?php

use Illuminate\Database\Seeder;
use App\Models\User;
use App\Models\Permission;
use App\Models\Role;

class UsersTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     * 创建基础权限以生成菜单和基础功能，其它权限登陆后创建
     */
    public function run()
    {
        //1
        $system = [
            'name' => 'system',
            'display_name' => '系统设置',
            'description' => '系统设置',
            'pid' => 0,
            'icon' => 'fa-cogs',
            'sort' => 99,
            'is_menu' => 1
        ];
        Permission::create($system);
        //2
        $usermanage = [
            'name' => 'user.index',
            'display_name' => '用户管理',
            'description' => '用户管理',
            'pid' => 1,
            'icon' => 'fa-user',
            'is_menu' => 1
        ];
        Permission::create($usermanage);
        //3
        $rolemanage = [
            'name' => 'role.index',
            'display_name' => '角色管理',
            'description' => '角色管理',
            'pid' => 1,
            'icon' => 'fa-users',
            'is_menu' => 1
        ];
        Permission::create($rolemanage);
        //4
        $permissionmanage = [
            'name' => 'permission.index',
            'display_name' => '权限管理',
            'description' => '权限管理',
            'pid' => 1,
            'icon' => 'fa-key',
            'is_menu' => 1
        ];
        Permission::create($permissionmanage);
        //5
        $createpermission = [
            'name' => 'permission.create',
            'display_name' => '创建权限',
            'description' => '创建权限',
            'pid' => 4,
            'is_menu' => 0
        ];
        Permission::create($createpermission);
        //6
        $storepermission = [
            'name' => 'permission.store',
            'display_name' => '保存权限',
            'description' => '保存权限',
            'pid' => 4,
            'is_menu' => 0
        ];
        Permission::create($storepermission);
        //7
        $createrole = [
            'name' => 'role.create',
            'display_name' => '创建角色',
            'description' => '创建角色',
            'pid' => 3,
            'is_menu' => 0
        ];
        Permission::create($createrole);
        //8
        $storerole = [
            'name' => 'role.store',
            'display_name' => '保存角色',
            'description' => '保存角色',
            'pid' => 3,
            'is_menu' => 0
        ];
        Permission::create($storerole);
        //9 permission
        $editrole = [
            'name' => 'role.edit',
            'display_name' => '编辑角色',
            'description' => '编辑角色',
            'pid' => 3,
            'is_menu' => 0
        ];
        Permission::create($editrole);
        //10 permission
        $updaterole = [
            'name' => 'role.update',
            'display_name' => '更新角色',
            'description' => '更新角色信息',
            'pid' => 3,
            'is_menu' => 0
        ];
        Permission::create($updaterole);
        //11 role
        $admin = [
            'name' => 'Admin',
            'display_name' => '管理员',
            'description' => '管理员',
        ];
        $role = Role::create($admin);
        $role->attachPermissions([1,2,3,4,5,6,7,8,9,10]);
        $user = [
            'username' => 'admin',
            'realname' => '管理员',
            'password' => 'admin',
            'sex' => '男',
            'status' => 1,
        ];
        $user = User::create($user);
        $user->attachRole($role);
    }
}
